package 蓝桥真题;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class 二分123 {
       static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
       static final int N=10000010;
       static int n;
       static long a[]=new long[N],sum[]=new long[N];
       static long find(long x){
    	     
    	      long l=1,r=N;
    	      while(l<r){
    	    	  long mid=l+r+1>>1;
    	          if(mid*(mid+1)<=x*2)
    	        	   l=mid;
    	          else r=mid-1;
    	      }
    	      return l;
       }
       public static void main(String[] ss) throws IOException {
    	      for(int i=1;i<N;i++){
    	    	  a[i]=a[i-1]+i;
    	    	  sum[i]=sum[i-1]+a[i];
    	      }
		      n=Integer.parseInt(br.readLine());
		      long res=0;
		      while(n-->0){
		    	   ss=br.readLine().split(" ");
		    	   long l=Long.parseLong(ss[0]),r=Long.parseLong(ss[1]);
		    	   long ln=find(l),rn=find(r),pre=l-ln*(ln+1)/2,pos=r-(1+rn)*rn/2;
		    	   
		    	   res=a[(int)rn]-a[(int)ln]-(pre*(pre-1))/2+((pos+1)*pos)/2;
		    	   if(ln==1)res+=1;
		    	   System.out.println(res);
		      }
	}
}
